package com.lunhui.service.provider.common;

import java.io.Serializable;

/**
 * @author renminghe-kg
 */
public class Result<T> implements Serializable {
    private static final long serialVersionUID = -5080829816708093741L;

    public T result;
    public Integer errorCode;
    public String errorMessage;

    public T getResult() {
        return this.result;
    }

    public void setResult(T result) {
        this.result = result;
    }

    public Integer getErrorCode() {
        return this.errorCode;
    }

    public void setErrorCode(Integer errorCode) {
        this.errorCode = errorCode;
    }

    public String getErrorMessage() {
        return this.errorMessage;
    }

    public void setErrorMessage(String errorMessage) {
        this.errorMessage = errorMessage;
    }

    public Result(T result, String errorMessage) {
        this.result = result;
        this.errorMessage = errorMessage;
    }

    public Result(T result, Integer errorCode, String errorMessage) {
        this.result = result;
        this.errorCode = errorCode;
        this.errorMessage = errorMessage;
    }

    public static <T> Result<T> ok(T result) {
        return new Result<T>(result, null);
    }

    public static <T> Result<T> ok() {
        return new Result<T>(null, null);
    }

    public static <T> Result<T> fail(String errorMessage) {
        return new Result<T>(null, errorMessage);
    }

    public static <T> Result<T> fail(Integer errorCode, String errorMessage) {
        return new Result<T>(null, errorCode, errorMessage);
    }

    public static <T> Result<T> fail(T t, String error) {
        return new Result<T>(t, error);
    }


    public boolean isSuccess() {
        return (getErrorCode() == null);
    }

}